package com.highspeed.bdk.gateway.socket.analyze.message.gui.resolver;

import com.highspeed.bdk.gateway.Util;
import com.highspeed.bdk.gateway.socket.analyze.message.gui.base.MessageResolver;

import java.util.Map;

/**
 * 3.9逻辑链路消息查询的反馈包
 * typedef struct _logicLink
 * {
 * U32 startPortId; //链路起点Id 16-bit rionet id + 16-bit portId
 * U32 endPortId;//链路终点Id  16-bit rionet id + 16-bit portId
 * U32  startPhyAddr; //起始端口的物理地址
 * U32  endPhyAddr;  //未端口的物理地址
 * U8 appNameLen;
 * char AppName[APP_NAME_MAX_LEN]; //考虑4 字节对齐的问题
 * U8  peerAppNameLen;
 * char peerAppName[APP_NAME_MAX_LEN];
 * U8  resvd: 1,
 * backup: 1, //主链路 or 备链路,0 主，1 备
 * defaultLogic: 2, // 1 默认通道，0 应有通道
 * linkMode: 4; //0001 面向连接，0010面向无连接，0100多播模式，1000单播模式；取值为以上组合
 * U8 inOut; //方向 0:in  1:out  2:inout
 * U8 isSyn;// 1 同步,0 不同步
 * U8 reseved;
 * } LogicLinkFbData;
 */
public class LogicLinkResolver extends MessageResolver {

    @Override
    protected Map doResolveBody(byte[] response) {
        short startRionetId = Util.getShort(response, getOffset());
        offset2();
        short startPortId = Util.getShort(response, getOffset());
        offset2();
        logger.info("链路起点rionetId............." + startRionetId + ", portId.........." + startPortId);

        short endRionetId = Util.getShort(response, getOffset());
        offset2();
        short endPortId = Util.getShort(response, getOffset());
        offset2();
        logger.info("链路起点rionetId............." + endRionetId + ", portId.........." + endPortId);

        int startPhyAddr = Util.getInt(response, getOffset());
        offset4();
        logger.info("startPhyAddr.........." + startPhyAddr);

        int endPhyAddr = Util.getInt(response, getOffset());
        offset4();
        logger.info("endPhyAddr.........." + endPhyAddr);

        int appNameLen = Util.getByte(response, getOffset());
        offset1();
        logger.info("appNameLen.........." + appNameLen);

        //获取长度数值，遍历长度char
        String appName = Util.subBytesToString(response, getOffset(), appNameLen);
        offsetN(appNameLen);
        logger.info("appName.........." + appName);

        byte peerAppNameLen = Util.getByte(response, getOffset());
        offset1();
        logger.info("peerAppNameLen.........." + peerAppNameLen);

        String peerAppName = Util.subBytesToString(response, getOffset(), peerAppNameLen);
        offsetN(peerAppNameLen);
        logger.info("peerAppName.........." + peerAppName);

        byte u8 = Util.getByte(response, getOffset());
        offset1();
        logger.info("u8.........." + u8);

        byte inOut = Util.getByte(response, getOffset());
        offset1();
        logger.info("inOut.........." + inOut);

        byte isSyn = Util.getByte(response, getOffset());
        offset1();
        logger.info("isSyn.........." + isSyn);

        byte reseved = Util.getByte(response, getOffset());
        offset1();
        logger.info("reseved.........." + reseved);

        return getContainer();
    }
}
